const express = require('express');
let router = express.Router();
var Category = require('../models/category');
var Content = require('../models/content');
router.use(function (req, res,next) {
    Category.find().then(function (category) {
        req.category = category
    })
    next();
})
router.get('/',function (req, res, next) {
    Content.find().then(function (content) {
        res.render('main/index',{
            userInfo:req.userInfo,
            categorys:req.category,
            contents:content
        });
    })
})
router.get('/conteninfo',function (req, res, next) {
    var contentid = req.query.contentid;
    Content.findOne({_id:contentid}).then(function (contentinfo) {
        contentinfo.view++;
        contentinfo.save();
        res.render('main/contentInfo',{
            userInfo:req.userInfo,
            categorys:req.category,
            contentinfo:contentinfo
        })
    })

})

module.exports = router;